//
//  HHGuideVeiw.m
//  01-百思不得姐
//
//  Created by hehuafeng on 2016/12/11.
//  Copyright © 2016年 hehuafeng. All rights reserved.
//

#import "HHGuideVeiw.h"

@implementation HHGuideVeiw
/**
 * 移除通知引导
 */
- (IBAction)guideButtonClick {
    // 1. 从父控件移除
    [self removeFromSuperview];
}

/**
 * 快速创建通知引导view
 */
+ (instancetype)guideView{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}

/**
 * 显示引导通知view
 */
+ (void)show{
    // 1. 获取当前版本号
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    
    // 2. 获取偏好设置中版本号
    NSString *version = [[NSUserDefaults standardUserDefaults] stringForKey:@"version"];
    
    // 3. 判断当前版本号与偏好设置中版本号是否一致
    if (![currentVersion isEqualToString:version]) {
        // 4. 获取window
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        
        // 5. 将通知引导页添加到窗口上面
        HHGuideVeiw *gudieView = [self guideView];
        gudieView.frame = window.bounds;
        [window addSubview:gudieView];
        
        // 6. 存储当前版本号
        [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:@"version"];
        
        // 7. 立即同步到偏好设置
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}
@end
